import Vue from 'vue'
import VueRouter from 'vue-router'
import Frame from "../src/components/frame.vue";
import {
	RouterTabRoutes
} from 'vue-router-tab';

const importPage = view => () =>
	import(`../page/${view}.vue`)

Vue.use(VueRouter);

const routes = [
	{
		path: '/',
		component: Frame,
		meta: {
			title: '主页' // 页签标题
		},
		children: [
			// 引入 RouterTab 内置路由以支持 iframe 页签
			...RouterTabRoutes,
			{
				path: '/', // 默认页和父级路由一致
				name: 'index',
				component: importPage('index'),
				meta: {
					title: '主页' // 页签标题
				}
			},
			{
				path: '/user',
				name: 'user',
				component: importPage('user/list'),
				meta: {
					title: '用户信息' // 页签标题
				}
			},
			{
				path: '/user/new',
				name: 'user_new',
				component: importPage('user/new'),
				meta: {
					title: '用户新增' // 页签标题
				}
			},
			{
				path: '/user/detail',
				name: 'user_detail',
				component: importPage('user/detail'),
				meta: {
					title: '用户详情' // 页签标题
				}
			},
			{
				path: '/role',
				name: 'role',
				component: importPage('role/list'),
				meta: {
					title: '角色列表' // 页签标题
				}
			},
			{
				path: '/role/new',
				name: 'role_new',
				component: importPage('role/new'),
				meta: {
					title: '新增角色' // 页签标题
				}
			},
			{
				path: '/role/detail',
				name: 'role_detail',
				component: importPage('role/detail'),
				meta: {
					title: '角色详细' // 页签标题
				}
			},
			{
				path: '/permission',
				name: 'permission',
				component: importPage('permission/list'),
				meta: {
					title: '权限列表' // 页签标题
				}
			},
			{
				path: '/permission/new',
				name: 'permission_new',
				component: importPage('permission/new'),
				meta: {
					title: '新增权限' // 页签标题
				}
			},
			{
				path: '/permission/detail',
				name: 'permission_detail',
				component: importPage('permission/detail'),
				meta: {
					title: '权限详细' // 页签标题
				}
			},
			
			
			{
				path: '/distributor',
				name: 'distributor',
				component: importPage('distributor/list'),
				meta: {
					title: '经销商列表' // 页签标题
				}
			},
			{
				path: '/distributor/new',
				name: 'distributor_new',
				component: importPage('distributor/new'),
				meta: {
					title: '新增经销商' // 页签标题
				}
			},
			
			{
				path: '/category',
				name: 'category',
				component: importPage('category/list'),
				meta: {
					title: '分类列表' // 页签标题
				}
			},
			{
				path: '/category/new',
				name: 'category_new',
				component: importPage('category/new'),
				meta: {
					title: '新增分类' // 页签标题
				}
			},
			{

				path: '/client',
				name: 'client',
				component: importPage('client/list'),
				meta: {
					title: '客户列表' // 页签标题
				}
			},
			
			
			{
				path: '/client/detail',
				name: 'client_detail',
				component: importPage('client/detail'),
				meta: {
					title: '客户详情' // 页签标题
				}
			},
			
			
			{

				path: '/category/detail',
				name: 'category_detail',
				component: importPage('category/detail'),
				meta: {
					title: '分类详细' // 页签标题
				}
			},
			{
				path: '/about',
				name: 'about',
				component: importPage('about/about'),
				meta: {
					title: '关于我们' // 页签标题
				}
			},
			
			{
				path: '/product',
				name: 'product',
				component: importPage('product/list'),
				meta: {
					title: '产品列表' // 页签标题
				}
			},
			{
				path: '/product/new',
				name: 'product_new',
				component: importPage('product/new'),
				meta: {
					title: '新增产品' // 页签标题
				}
			},
			{
				path: '/product/detail',
				name: 'product_detail',
				component: importPage('product/detail'),
				meta: {
					title: '产品详细' // 页签标题
				}
			},
			{
				path: '/sample',
				name: 'sample',
				component: importPage('sample/list'),
				meta: {
					title: '施工案例列表' // 页签标题
				}
			},
			{
				path: '/sample/detail',
				name: 'sample_detail',
				component: importPage('sample/detail'),
				meta: {
					title: '案例详情' // 页签标题
				}
			},
			{
				path: '/sample/new',
				name: 'sample_new',
				component: importPage('sample/new'),
				meta: {
					title: '新增案例' // 页签标题
				}
			},
			
			{
				path: '/adv',
				name: 'adv',
				component: importPage('adv/list'),
				meta: {
					title: '广告列表' // 页签标题
				}
			},
			
			{
				path: '/adv/new',
				name: 'adv_new',
				component: importPage('adv/new'),
				meta: {
					title: '新增广告' // 页签标题
				}
			},
			
			{
				path: '/adv/detail',
				name: 'adv_detail',
				component: importPage('adv/detail'),
				meta: {
					title: '广告详情' // 页签标题
				}
			},
			
			{
				path: '/page/:id',
				name: 'Page',
				component: importPage('Page'),
				meta: {
					key: 'path',
					title(route) {
						return `Page ${route.params.id}`
					}
				}
			}
		]
	},
	{
		path: '/dashboard',
		name: 'dashboard',
		component: importPage('dashboard/dashboard'),
	}
];

const router = new VueRouter({
	routes
});
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

export default router;
